//
//  BKSCCommon.m
//  bestkeep
//
//  Created by 毛韶谦 on 2016/11/3.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKSCCommon.h"


NSString *const BKSCLocalizableTableName = @"BKCMBuyCarLocalizable";

@implementation BKSCCommon

+(NSString *)localizedStringWithKey:(NSString *)key {
    return NSLocalizedStringFromTable(key, BKSCLocalizableTableName, nil);
}


#pragma mark -  字典转json
+ (NSString*)dictionaryToJson:(NSDictionary *)dic{
    NSError *parseError = nil;
    NSData *jsonData = nil;
    if (dic == nil) {
        return nil;
    }
    else{
        jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
        NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        return str;
    }
}
#pragma mark -  数组转json
+(NSString *)arrayToJson:(NSArray *)arr{
    NSError *parseError = nil;
    NSData *jsonData = nil;
    if (arr == nil) {
        return nil;
    }
    else{
        jsonData = [NSJSONSerialization dataWithJSONObject:arr options:NSJSONWritingPrettyPrinted error:&parseError];
        NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        return str;
    }
    
}

+ (NSString *)bkscServicesURL:(NSString *)url
{
    NSString *servicesURL = ApplicationEnvironmentProduction ? @"http://api.bestkeep.cn" : @"http://api.test.bestkeep.cn";
    return [NSString stringWithFormat:@"%@/%@",servicesURL, url];
}

+ (UIColor *)fromHexValue:(NSUInteger)hex {
    NSUInteger a = ((hex >> 24) & 0x000000FF);
    float fa = ((0 == a) ? 1.0f : (a * 1.0f) / 255.0f);
    
    return [BKSCCommon fromHexValue:hex alpha:fa];
}

+ (UIColor *)fromHexValue:(NSUInteger)hex alpha:(CGFloat)alpha {
    if ( hex == 0xECE8E3 ) {
        
    }
    NSUInteger r = ((hex >> 16) & 0x000000FF);
    NSUInteger g = ((hex >> 8) & 0x000000FF);
    NSUInteger b = ((hex >> 0) & 0x000000FF);
    
    float fr = (r * 1.0f) / 255.0f;
    float fg = (g * 1.0f) / 255.0f;
    float fb = (b * 1.0f) / 255.0f;
    
    return [UIColor colorWithRed:fr green:fg blue:fb alpha:alpha];
}


@end
